const router = require('koa-router')()
const path = require('path')
const fs = require('fs')

router.prefix('/download')

router.get('/file', async (ctx, next) => {
  const file = fs.createReadStream(
    path.join(__dirname, `../public/file/测试文件.txt`)
  )

  ctx.set({
    'Content-Disposition': `attachment;filename=${encodeURIComponent(
      '文件.txt'
    )}`,
  })
  ctx.body = file
})

module.exports = router
